<%--
 *  File:    UserSummary.jsp
 *  @Author: Langerwang 
 *  Date:    2001/11/4
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>



<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.UserSummary");  
%>

<% //--------------------------------------  variant and initialization --%>
<%
	String strModuleName = "UPM";
  	String strTableName = "ovuser";
	String privilegeCode = "Z0102,L401";
	String contextPath = request.getContextPath();
%>



<%
  	//get current userinfo
  	HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
	String languagecode = (String)session.getAttribute("languagecode");
  	Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
  	String strCurUserName = (String)CurUserInfo.get("username");
  	Integer nCurUserId = (Integer)CurUserInfo.get("userid");
  	String isPrimaryAdmin = (String)CurUserInfo.get("isprimaryadmin");
  	if(isPrimaryAdmin == null)
  	{
    	isPrimaryAdmin = "";
  	} 
  	//give permission
  	boolean bCanUpdatePrimaryAdmin = true;
  	if(!isPrimaryAdmin.equalsIgnoreCase("Y"))
  	{
    	bCanUpdatePrimaryAdmin = false;
  	} 
%>

<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>


<html>
<head>
<title>UserSummary</title>
<PageFlow:CheckPageFlow pageName="usersummary"/>
<%@ include file="/inc/InitEdit.inc" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../../js/FuncLib.js"></script>
<%@ include file="/rpt/ReportURL.inc"%>
<script>
isRunning=false;
</script>
<%@ include file="/inc/SummaryDivision.inc" %>

<% //--------------------------------------  output variant from pageflow --%>
<%
  	String orgname = (String)CurUserInfo.get("orgname");

  	Integer nOrgId = (Integer)pageContext.getAttribute("orgid");
  	Vector userSummary = (Vector)pageContext.getAttribute("usersummary");
  	if(userSummary == null)
    	userSummary = new Vector();
%>
<script>
function clickUser(id,val)
{
  document.usersummaryform.userid.value = id;
  document.usersummaryform.ispa.value = val;
}
function poporg()
{
  window.open("../ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>&selectoption=owner&languagecode=<%= strLanguageCode %>", "newwindow", "height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
function page_setOrg(id,name)
{
  document.usersummaryform.orgid.value = id;
  document.usersummaryform.orgname.value = name;
  page_summary('search');
}

function page_delete()
{
  var uid = document.usersummaryform.userid.value;
  var ispaval = document.usersummaryform.ispa.value; 
  if(uid == null || uid.length == 0 || uid == "" || uid == "-1")
    return;
  if(uid == "<%=JspHelper.filterNull( nCurUserId )%>")
  {
    alert("<%= message.getMessageDesc("CAN_NOT_DEL_IT") %>");
    return;
  }
  if(ispaval == "Y" || ispaval == "y")
  {
    alert("<%= message.getMessageDesc("NO_RIGHT") %>");
    return;
  }  
  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>");
  if(!flag)
    return;
  document.usersummaryform.actionname.value = "delete";
  isRunning = true;
  document.usersummaryform.submit();
}
function page_edit()
{
  var uid = document.usersummaryform.userid.value;
  if(uid == null || uid.length == 0 || uid == "" || uid == "-1")
    return;
  self.location.href = "UserEdit.jsp?<%= OvalTools.randomURL() %>&userid=" + uid + "&languagecode=<%= strLanguageCode %>&orgid=" + "<%=JspHelper.filterNull( nOrgId )%>";
  //alert(self.location.href);
}
function page_summary(actionvalue,orderbyname)
{
	//if(isRunning) return;
  var editform = summaryPrepare(usersummaryform,actionvalue,orderbyname);
  editform.action = "UserSummary.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}
function page_accreditinfo()
{
  var uid = document.usersummaryform.userid.value;
  if(uid == null || uid.length == 0 || uid == "" || uid == "-1")
      return;
  self.location.href ="UserAuthorityInfo.jsp?<%= OvalTools.randomURL() %>&userid=" + uid;     
}
function page_userauthoritycondition()
{
  var uid = document.usersummaryform.userid.value;
  if(uid == null || uid.length == 0 || uid == "" || uid == "-1")
     return;
  self.location.href ="UserAuthorityCondition.jsp?<%= OvalTools.randomURL() %>&userid=" + uid;
}
function page_userauthoritygrant()
{
  var uid = document.usersummaryform.userid.value;
  if(uid == null || uid.length == 0 || uid == "" || uid == "-1")
     return;
  self.location.href ="UserAuthorityGrant.jsp?<%= OvalTools.randomURL() %>&userid=" + uid;
}

function page_deptedit()
{
  if ( document.usersummaryform.editflag.value=='Disabled')
      return;
  var url='../../zstf/img/ZSTFUserDeptSummary.jsp?<%= OvalTools.randomURL() %>&userid='+usersummaryform.userid.value+'&username='+usersummaryform.username.value;
  self.location.href=url;
}

function page_export(){
	var searchname = document.usersummaryform.searchname.value;
	var searchvalue = document.usersummaryform.searchvalue.value;
	var languagecode = document.usersummaryform.languagecode.value;
	var url = "<%=reportURL%>/servlet/ExcecuteReport/ExportUser.sox?__folder=/ovalreport&sessionid=<%=session.getId()%>&languagecode=" + languagecode;
	if(searchvalue != "" && searchvalue != null){
		url += "&" + searchname + "=" + escape(encodeURI(searchvalue));
	}
	var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
    popwindow = window.open(url, "nwindow", strstatus);
}
function page_uploadexport(){
	var url = "<%=reportURL%>/servlet/ExcecuteReport/contactinfo.sox?__folder=/ovalreport&sessionid=<%=OvalTools.randomURL()%>";
	var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
    popwindow = window.open(url, "nwindow", strstatus);
}
function page_csv(){
	var url="<%=reportURL%>"+"/csv?__report=/ovalreport/usersummary.txt&<%=OvalTools.randomURL() %>"; 
	var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
    popwindow = window.open(url, "nwindow", strstatus);
}

function page_selectUser() {
		var status = "height=400, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
		var url = "<%=contextPath%>/img/UserSelectPop.jsp?o_thread=" + Math.random();
			
		if (typeof popwindow != 'undefined') popwindow.close();
		popwindow = window.open(url, "newwindow", status);
}
function page_setUser(id,code,name){
	document.usersummaryform.parentuserid.value=id;
	document.usersummaryform.parentusername.value=code;
	document.usersummaryform.parentemployeename.value=name;
}
function page_popBusinessarea()
  {
    if (typeof popwindow != 'undefined') popwindow.close();
    popwindow = window.open("<%=contextPath%>/masterdata/ogm/zylstdbusinessareapop.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>","newwindow", "height=300, width=800,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	
  }

  function setContact(id,type,name){
	document.usersummaryform.stdareatype.value=id;
	document.usersummaryform.strareaname.value=name;
  	//alert(document.busiareaeditform.stdareatype.value);
  }
  function page_clear(){
	document.usersummaryform.__username.value="";
	document.usersummaryform.__employeecode.value="";
	document.usersummaryform.__employeename.value="";
	document.usersummaryform.parentuserid.value="";
	document.usersummaryform.parentusername.value="";
	document.usersummaryform.parentemployeename.value="";
	document.usersummaryform.__deptid.options[0].selected=true;
	document.usersummaryform.jobtitle.options[0].selected=true;
	document.usersummaryform.status.options[0].selected=true;
	document.usersummaryform.stdareatype.value="";
	document.usersummaryform.strareaname.value="";
	
}



</script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

	<% //--------------------------------------  hidden form variant --%>
	<form name="usersummaryform" method="post" action="../../Dispatcher"  target="_parent">
    <input type="hidden" name="pagename" value="usersummary">
    <input type="hidden" name="actionname">   
    <oval:hidden name="orginfo" property="orgid"/>
    <input type="hidden" name="languagecode" value="<%=languagecode %>">   
	<% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
	
	<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr> 
    	<td valign="top"> 
        	<table width="100%" border="0" cellspacing="0">
          	<tr> 
            	<td class="summary_top" ></td> 
          	</tr>
        	</table>
        	<table width="100%" border="0" cellspacing="0" cellpadding="0" onkeydown="if(event.keyCode==13) page_summary('search');">
          	<tr> 
          	  <%//if(privilegeSet != null && privilegeSet.contains("1000000")){%>
              <td nowrap><%= label.getLabelName("L_OwnerOrg") + label.getLabelName("L_Colon") %></td><td>						  
            	<% if (pageContext.getAttribute("orginfo") == null) {%>
            	<input type="text" name="orgname" value="<%=JspHelper.filterNull( orgname )%>" size="30" readonly>
            	<%}else{%>            	
            	<input type="text" name="orgname" value="<oval:write name="orginfo" property="orgname"/>" size="30" readonly>
              <%}%>
              <a onclick="poporg()"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a></td>
              <%//}%>
				<td><%= label.getLabelName("L_UserCode") + label.getLabelName("L_Colon") %></td><td><custom:text property="__username"/></td>
				<td><%= label.getLabelName("L_UserNumber") + label.getLabelName("L_Colon") %></td><td><custom:text property="__employeecode"/></td>
				<td><%= label.getLabelName("L_UUserName") + label.getLabelName("L_Colon") %></td><td><custom:text property="__employeename"/></td>
				<td><!--  <%= label.getLabelName("L_Province") + label.getLabelName("L_Colon") %>--><%= label.getLabelName("L_employeenameUp") + label.getLabelName("L_Colon") %></td>
				<td><!--<custom:text property="regionname"/>-->
				<custom:text property="parentusername" size="10" onchange="page_cleancode('emp')" />
				 <a onclick="javascript:page_selectUser();">
				 <custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0" /></a> 
				 <custom:text property="parentemployeename" size="10" readonly="true" /> 
					<custom:hidden property="parentuserid"/>
				</td>
			</tr>
			<tr>
				<td><%= label.getLabelName("L_DefaultDeptName") + label.getLabelName("L_Colon") %></td>
				<td><custom:select optionInnerTextKey="deptname" optionsName="alldepts" property="__deptid" defaultValue="------" optionValueKey="deptid"
				defaultValueCost="null"/></td>
				<td><%= label.getLabelName("L_TitleName") + label.getLabelName("L_Colon") %></td>
				<td><custom:selectdic dictType="JobTitle" property="jobtitle" defaultValue="------" defaultValueCost="null"/></td>
				<td><%= label.getLabelName("L_Provicetdr") + label.getLabelName("L_Colon") %></td>
				<td><!--<custom:text property="businessareaname"/>-->
					<custom:hidden property="stdareatype" />
		           	<custom:text property="strareaname"/>
		           	<a onclick="page_popBusinessarea();"><custom:button type="3" value="*"/></a>
				</td>
				<td><%= label.getLabelName("L_Status") + label.getLabelName("L_Colon") %></td>
				<td><custom:selectdic dictType="Status" property="status" valueCriteria="28,41" defaultValue="------" defaultValueCost="null"/></td>
				<td colspan="2"><a href="javascript:page_summary('search')"><img src="/oval/images/cn/go_fy.gif" border="0" style="border: 1 solid #000000"></a>&nbsp;&nbsp;<button button type="button" onclick="page_clear()" class="button1" name="re" value="clear"><%= label.getLabelName("L_Clear") %></button></td>
			</tr>
            </table>
            </td>
          </tr>
        </table>
        
        <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="0">
        
        <% //--------------------------------------  summary header --%>
        <tr bgcolor="#ACBCCA" class="deepblue-left">
        	<td width="15" class="title_center">&nbsp;</td>
            <td width="100" class="title_center"><a href="javascript:page_summary('orderby','username')"><%= label.getLabelName("L_UserCode") %></a></td>
			<td width="60" class="title_center"><a href="javascript:page_summary('orderby','employeecode')"><%= label.getLabelName("L_UserNumber") %></a></td>
            <td width="60" class="title_center"><a href="javascript:page_summary('orderby','employeename')"><%= label.getLabelName("L_UUserName") %></a></td>
            <td width="100" class="title_center"><a href="javascript:page_summary('orderby','deptcode')"><%= label.getLabelName("L_DefaultDeptName") %></a></td>
            <td width="250" class="title_center"><a href="javascript:page_summary('orderby','valuename')"><%= label.getLabelName("L_TitleName") %></a></td>
            <!-- <td width="120" class="title_center"><a href="javascript:page_summary('orderby','passwordexpiredate')"><%= label.getLabelName("L_PasswordExpireDate") %></a></td> -->
            <td class="title_center" width="120"><a href="javascript:page_summary('orderby','strareaname')"><%= label.getLabelName("L_Provicetdr") %></a></td>
            <td width="120" class="title_center"><a href="javascript:page_summary('orderby','parentemployeename')"><%= label.getLabelName("L_employeenameUp")+label.getLabelName("L_ItemName1") %></a></td>
            <td width="40" class="title_center"><a href="javascript:page_summary('orderby','statusname')"><%= label.getLabelName("L_Status") %></a></td>
       	</tr>
        
        <% //--------------------------------------  default value definition --%>
        <%
        	int i = 0;
            String strClassType = new String();   
            Integer nDefaultUserId = new Integer(-1); 
            String strIsPrimaryAdmin = "";
            boolean bHasChecked = false;   
            String strDefaultIsDisabled="";
        		String strDefaultUserName="";                                   
      	%>
        
        <% //--------------------------------------  loop results --%>
        <logic:iterate id="usersum" collection="<%= userSummary %>">                      
        <%
        	HashMap userMap = (HashMap)pageContext.getAttribute("usersum"); 
            String strUserName = (String)userMap.get("username");  
            String userIsPrimaryAdmin = (String)userMap.get("isprimaryadmin");
            String strIsDisabled = new String("");
            String strIsChecked = new String("");
            if(i%2 == 1)
            {
              	strClassType = "td-listrom";
            }else{                    
              	strClassType = "";
            }
            if(!bCanUpdatePrimaryAdmin && "Y".equalsIgnoreCase(userIsPrimaryAdmin) && nCurOrgId.equals((Integer)userMap.get("orgid")) )
            {
               strIsDisabled = new String(" Disabled ");
               userMap.put("userid","-1");
            } 
            else if(!bHasChecked)
            {
                strIsChecked = "Checked";
                bHasChecked = true;
                nDefaultUserId = (Integer)(userMap.get("userid"));
                strIsPrimaryAdmin = (String)(userMap.get("isprimaryadmin"));
                strDefaultUserName= (String)(userMap.get("username"));
                strDefaultIsDisabled = strIsDisabled;
            }
            i++;                         
          %>
          
     	<tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'"  onClick="javascript:radiotrue('user<%=JspHelper.filterNull( i )%>');clickUser('<%=JspHelper.filterNull( userMap.get("userid") )%>','<%=JspHelper.filterNull( userMap.get("isprimaryadmin") )%>');" class="<%=JspHelper.filterNull( strClassType )%>"> 
        	<td width="5%" class="<%=JspHelper.filterNull( strClassType )%>">
            	<input type="radio" id="user<%=JspHelper.filterNull( i )%>"name="checkuser" <%=JspHelper.filterNull( strIsDisabled )%> value=<%=JspHelper.filterNull( userMap.get("userid") )%> class="checkbox" <%=JspHelper.filterNull( strIsChecked )%>>
            </td>
            <td width="10%" class="<%=JspHelper.filterNull( strClassType )%>"><a href="userinfo.jsp?<%= OvalTools.randomURL() %>&userid=<%=JspHelper.filterNull( userMap.get("userid") )%>"><%=JspHelper.filterNull( userMap.get("username") )%></a></td>
			<td width="10%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("employeecode") )%></td>
            <td width="15%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("employeename") )%></td>
            <td width="15%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("deptname") )%></td>
			<td width="15%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("valuename") )%></td>
<!--             <td width="14%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%= OvalTools.dateToString(userMap.get("passwordstartdate"),(String)session.getAttribute("dateformat")) %></td>
            <td width="15%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%= OvalTools.dateToString(userMap.get("passwordexpiredate"),(String)session.getAttribute("dateformat")) %></td> -->
            <td width="10%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("strareaname") )%></td>
            <td width="10%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("parentemployeename") )%></td>
            <td width="10%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("statusname") )%></td>
     	</tr>
        </logic:iterate>                   
        
        <% //--------------------------------------  default value --%>       
        <input type="hidden" name="userid" value="<%=JspHelper.filterNull( nDefaultUserId )%>">
        <input type="hidden" name="ispa" value="<%=JspHelper.filterNull( strIsPrimaryAdmin )%>">
				<input type="hidden" name="username" value="<%=JspHelper.filterNull( strDefaultUserName )%>">  
    		<input type="hidden" name="editflag" value="<%=JspHelper.filterNull( strDefaultIsDisabled )%>">
        <% //--------------------------------------  flipping page --%>
    	<%@ include file="/inc/SummaryAction.inc" %>
          
        </table>
        
        <% //--------------------------------------  page operation button --%>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        	<tr> 
            	<td class="summary_top" ></td>
          	</tr>
          	<tr> 
            	<td class="td_center">
            		<a onclick="self.location.href='UserEdit.jsp?<%= OvalTools.randomURL() %>&orgid=<%=JspHelper.filterNull( nOrgId )%>';"><custom:button type="1" label="L_New" imgsrc="new.gif" border="0" style="width:60"/></a>
            		<a onclick="page_edit()"><custom:button type="1" label="L_Edit" imgsrc="edit.gif" border="0" style="width:60"/></a>
            		<!--  <a onclick="page_delete()"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a>
            		<a onclick="page_accreditinfo();"><custom:button type="1" label="L_Accreditinfo" imgsrc="accreditinfo.gif" border="0" style="width:60"/></a>
            		<a onclick="page_userauthoritycondition();"><custom:button type="1" label="L_Privilege_condition" imgsrc="privilege_condition.gif" border="0" style="width:60"/></a>
            		<a onclick="page_userauthoritygrant();"><custom:button type="1" label="L_AuthorityGrant" imgsrc="authoritygrant.gif" border="0" style="width:60"/></a>
            		<a onclick="page_export()"><custom:button type="1" label="L_Execcd" imgsrc="finish.gif" border="0" style="width:60"/></a>-->
            		<a onclick="page_csv()"><custom:button type="1" label="L_Execcd" imgsrc="finish.gif" border="0" style="width:60"/></a>
            		<a onclick="page_uploadexport()"><custom:button type="1" label="L_Upload_Derived" imgsrc="finish.gif" border="0" style="width:60"/></a>
								<!--<a onclick="page_deptedit();"><input type="button" class="button1" value="\ufffd\ufffd\ufffd\ufffd\u03ac\ufffd\ufffd" border="0" style="width:60"></a>-->
            	</td>
          	</tr>
        </table>
        
  	</td>
</tr>
</table>
</form>
</body>
</html>
<script>
isRunning=false;
</script>
